package com.eling.elcms.travel.service.impl;

import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.travel.dao.IApprovalDefineDao;
import com.eling.elcms.travel.model.ApprovalDefine;
import com.eling.elcms.travel.service.IApprovalDefineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ApprovalDefineServiceImpl extends
		GenericManagerImpl<ApprovalDefine, Long> implements
		IApprovalDefineService {
	IApprovalDefineDao approvalDefineDao;
//	@Autowired
//	private IApprovalInstanceService approvalInstanceService;

	@Autowired
	public void setDao(IApprovalDefineDao dao) {
		this.dao = dao;
	}

	@Override
	public ApprovalDefine blockup(ApprovalDefine approvalDefine) {
		//checkUnfinishedApprovalInstance(approvalDefine);
		approvalDefine.setStatus(ApprovalDefine.Status.BlockUp);
		return save(approvalDefine);
	}

	/**
	 * 停用校验是否有没完成的审批实例
	 * @param approvalDefine
	 */
//	private void checkUnfinishedApprovalInstance(ApprovalDefine approvalDefine) {
//		ApprovalInstance cond = new  ApprovalInstance();
//		cond.setApprovalDefine(approvalDefine);
//		List<ApprovalInstance> list= approvalInstanceService.query(cond);
//		for (ApprovalInstance approvalInstance : list) {
//			if (approvalInstance.getFlowStatus()==FlowStatus.Initial 
//					|| 
//				approvalInstance.getFlowStatus()==FlowStatus.Commited 	
//					||
//				approvalInstance.getFlowStatus()==FlowStatus.Approvaling		
//					) {
//				throw new BusinessException("该审批流程还有未完成的审批单，请全部完成后再停用");
//			}
//		}
//	}
}
